f = open('18.in', 'r');

dp1 = [0 for i in xrange(16)]

for line in f:
    line = [int(x) for x in line.split(' ')]
    if len(line) == 1:
        dp1[0] = line[0]
        continue
    idx = 0
    dp2 = [0 for i in xrange(16)]
    for x in line:
        dp2[idx] = max(dp2[idx], x + dp1[idx])
        if idx > 0:
            dp2[idx] = max(dp2[idx], x + dp1[idx-1])
        idx += 1
    dp1 = dp2
    print dp1
print max(dp1)


